var itemsDefHeight = {};
var win_ancho = $(window).width();
var win_alto  = $(window).height();
function ItemsHeight() {
    win_ancho = $(window).width();
    win_alto  = $(window).height();
    var menu_h = getMenuHeight();
    var ItemsHeight = (viewportHeight() - menu_h) / (viewportWidth() < 480 ? 3 : 2);
    var h = viewportHeight() - menu_h,
        $this;
    $('.page-resize').each(function(i) {
        // $(this).height() writes incorrect values (?)
        $(this).css('height', (itemsDefHeight[this.id] && itemsDefHeight[this.id] > h ? itemsDefHeight[this.id] : h) + 'px');
    });
}
function PositionHeader(scrollTop) {
    if (viewportWidth() >= 768) {
        if (scrollTop >= ($(window).height() - getMenuHeight())) {
            $('body').css('padding-top', '100px');
            $('nav').addClass('fixed');
        } else {
            $('body').css('padding-top', '');
            $('nav').removeClass('fixed');
        }
    }
}
$(window).resize(function() {
    ItemsHeight();
});
ItemsHeight();
$(window).scroll(function(e) {
    var scrollTop = $(window).scrollTop();
    var scrollTop2 = $(window).scrollTop() + getMenuHeight();
    var win_alto = $(window).height();

    /* Header */
    PositionHeader(scrollTop);

    /* Nav */
    /*
    if (scrollTop2 >= $("#page-experience").offset().top) {
        $('#header .navscroll').removeClass('active');
        $('#header .navscroll[data-idpage="page-experience"]').addClass('active');
        $('.nav-experience .navscroll').removeClass('active');
    } else {
        $('#header .navscroll').removeClass('active');
    }
    */
    
});
$('.navscroll').click(function(event) {
    event.preventDefault();
    $('nav .navscroll.active').removeClass('active');
    $(this).addClass('active');
    var anchor = $(this).data('id');
    if (anchor)
        $('html, body').stop().animate({
            scrollTop: $('#' + anchor).offset().top - getMenuHeight()
        }, 1000);
});
$(window).load(function() {
    PositionHeader($(window).scrollTop());
    $(".fancybox").fancybox();
});
function viewportWidth() {
    return document.documentElement.clientWidth || document.body.clientWidth;
}
function viewportHeight() {
    return document.documentElement.clientHeight || document.body.clientHeight;
}
function getMenuHeight() {
    return viewportWidth() < 768 ? 0 : 100;
}